
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize upwins;
@synthesize cpwins;
@synthesize personwins;
@synthesize compwins;
@synthesize ties;
@synthesize winner;
@synthesize userpic;
@synthesize comppic;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setUserpic:nil];
    [self setComppic:nil];
    [self setPersonwins:nil];
    [self setCompwins:nil];
    [self setTies:nil];
    [self setWinner:nil];
    [self setUpwins:nil];
    [self setCpwins:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)rock:(id)sender {
    [userpic setImage:[UIImage imageNamed:@"fred.jpeg"]];
    totalturns ++;

    
    int comppicker = arc4random() % 3;
    switch(comppicker){
        case 0:
            [comppic setImage:[UIImage imageNamed:@"fred.jpeg"]];
            totalties ++;
            winner.text = @"It's a tie!";
            break;
        case 1:
            [comppic setImage:[UIImage imageNamed:@"bob.jpeg"]];
            computerwins ++;
            winner.text = @"Computer won!";
            break;
        case 2:
            [comppic setImage:[UIImage imageNamed:@"edward.gif"]];
            userwins ++;
            winner.text = @"You won!";
            break;
    } 
    compwins.text = [NSString stringWithFormat:@"%d",computerwins];
    personwins.text = [NSString stringWithFormat:@"%d",userwins];
    ties.text = [NSString stringWithFormat:@"%d",totalties];
    
    cp = (float)computerwins/(float)totalturns*100;
    cpwins.text = [NSString stringWithFormat:@"%f %%",cp];
    up = (float)userwins/(float)totalturns*100;
    upwins.text = [NSString stringWithFormat:@"%f %%",up];
}

- (IBAction)paper:(id)sender {
    [userpic setImage:[UIImage imageNamed:@"bob.jpeg"]];
    totalturns ++;
    
    int comppicker = arc4random() % 3;
    switch(comppicker){
        case 0:
            [comppic setImage:[UIImage imageNamed:@"fred.jpeg"]];
            userwins ++;
            winner.text = @"You won!";
            break;
        case 1:
            [comppic setImage:[UIImage imageNamed:@"bob.jpeg"]];
            totalties ++;
            winner.text = @"It's a tie!";
            break;
        case 2:
            [comppic setImage:[UIImage imageNamed:@"edward.gif"]];
            computerwins ++;
            winner.text = @"Computer won!";
            break;
    }
    compwins.text = [NSString stringWithFormat:@"%d",computerwins];
    personwins.text = [NSString stringWithFormat:@"%d",userwins];
    ties.text = [NSString stringWithFormat:@"%d",totalties];
    
    cp = (float)computerwins/(float)totalturns*100;
    cpwins.text = [NSString stringWithFormat:@"%f %%",cp];
    up = (float)userwins/(float)totalturns*100;
    upwins.text = [NSString stringWithFormat:@"%f %%",up];
}

- (IBAction)scissors:(id)sender {
    [userpic setImage:[UIImage imageNamed:@"edward.gif"]];
    totalturns ++;
    
    int comppicker = arc4random() % 3;
    switch(comppicker){
        case 0:
            [comppic setImage:[UIImage imageNamed:@"fred.jpeg"]];
            computerwins ++;
            winner.text = @"Computer won!";
            break;
        case 1:
            userwins ++;
            winner.text = @"You won!";
            [comppic setImage:[UIImage imageNamed:@"bob.jpeg"]];
            break;
        case 2:
            [comppic setImage:[UIImage imageNamed:@"edward.gif"]];
            totalties ++;
            winner.text = @"It's a tie!";
            break;
    }
    compwins.text = [NSString stringWithFormat:@"%d",computerwins];
    personwins.text = [NSString stringWithFormat:@"%d",userwins];
    ties.text = [NSString stringWithFormat:@"%d",totalties];
    
    cp = (float)computerwins/(float)totalturns*100;
    cpwins.text = [NSString stringWithFormat:@"%f %%",cp];
    up = (float)userwins/(float)totalturns*100;
    upwins.text = [NSString stringWithFormat:@"%f %%",up];
}

@end
